package rnn.utilities;


public class GroupAvgCluster extends Element {
	public float[][] points;

	public GroupAvgCluster(float[] point) {
		this.points = new float[1][];
		this.points[0] = point;
	}

	public GroupAvgCluster(float[][] listPoints) {
		this.points = listPoints;
	}

	@Override
	public float sim(Element cluster) {
		GroupAvgCluster c = (GroupAvgCluster) cluster;
		float sum = 0;

		for (float[] c1 : points)
			for (float[] c2 : c.points) {
				sum += sim(c1, c2);
			}

		sum = sum / (c.points.length);

		return sum;
	}

	public GroupAvgCluster agglomerate(Element cluster) {
		GroupAvgCluster c1 = (GroupAvgCluster) cluster;
		float[][] newPointsList = new float[c1.points.length
				+ points.length][];

		System.arraycopy(c1.points, 0, newPointsList, 0, c1.points.length);
		System.arraycopy(points, 0, newPointsList, c1.points.length,
				points.length);

		GroupAvgCluster c = new GroupAvgCluster(newPointsList);
		System.out.println("agglomerate to " + newPointsList.length);
		return c;
	}

	@Override
	public String toString() {
		String txt = "";
		txt += "size: " + points.length + "\n";

		// for (float[] f : points) {
		// txt += "\t" + Arrays.toString(f) + "\n";
		// }
		txt += "\n";

		return txt;
	}

}